package com.wbw.ssb.mbg.mapper;

import static com.wbw.ssb.mbg.mapper.SystemDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.wbw.ssb.mbg.entity.System;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface SystemMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn.columnList(id, company, contacts, tel, temperatureAlarmThreshold, humidityAlarmThreshold, smogAlarmThreshold);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<System> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("SystemResult")
    Optional<System> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="SystemResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="company", property="company", jdbcType=JdbcType.VARCHAR),
        @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
        @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
        @Result(column="temperature_alarm_threshold", property="temperatureAlarmThreshold", jdbcType=JdbcType.DOUBLE),
        @Result(column="humidity_alarm_threshold", property="humidityAlarmThreshold", jdbcType=JdbcType.DOUBLE),
        @Result(column="smog_alarm_threshold", property="smogAlarmThreshold", jdbcType=JdbcType.DOUBLE)
    })
    List<System> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(System record) {
        return MyBatis3Utils.insert(this::insert, record, system, c ->
            c.map(company).toProperty("company")
            .map(contacts).toProperty("contacts")
            .map(tel).toProperty("tel")
            .map(temperatureAlarmThreshold).toProperty("temperatureAlarmThreshold")
            .map(humidityAlarmThreshold).toProperty("humidityAlarmThreshold")
            .map(smogAlarmThreshold).toProperty("smogAlarmThreshold")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(System record) {
        return MyBatis3Utils.insert(this::insert, record, system, c ->
            c.map(company).toPropertyWhenPresent("company", record::getCompany)
            .map(contacts).toPropertyWhenPresent("contacts", record::getContacts)
            .map(tel).toPropertyWhenPresent("tel", record::getTel)
            .map(temperatureAlarmThreshold).toPropertyWhenPresent("temperatureAlarmThreshold", record::getTemperatureAlarmThreshold)
            .map(humidityAlarmThreshold).toPropertyWhenPresent("humidityAlarmThreshold", record::getHumidityAlarmThreshold)
            .map(smogAlarmThreshold).toPropertyWhenPresent("smogAlarmThreshold", record::getSmogAlarmThreshold)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<System> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<System> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<System> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<System> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, system, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(System record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(company).equalTo(record::getCompany)
                .set(contacts).equalTo(record::getContacts)
                .set(tel).equalTo(record::getTel)
                .set(temperatureAlarmThreshold).equalTo(record::getTemperatureAlarmThreshold)
                .set(humidityAlarmThreshold).equalTo(record::getHumidityAlarmThreshold)
                .set(smogAlarmThreshold).equalTo(record::getSmogAlarmThreshold);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(System record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(company).equalToWhenPresent(record::getCompany)
                .set(contacts).equalToWhenPresent(record::getContacts)
                .set(tel).equalToWhenPresent(record::getTel)
                .set(temperatureAlarmThreshold).equalToWhenPresent(record::getTemperatureAlarmThreshold)
                .set(humidityAlarmThreshold).equalToWhenPresent(record::getHumidityAlarmThreshold)
                .set(smogAlarmThreshold).equalToWhenPresent(record::getSmogAlarmThreshold);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(System record) {
        return update(c ->
            c.set(company).equalTo(record::getCompany)
            .set(contacts).equalTo(record::getContacts)
            .set(tel).equalTo(record::getTel)
            .set(temperatureAlarmThreshold).equalTo(record::getTemperatureAlarmThreshold)
            .set(humidityAlarmThreshold).equalTo(record::getHumidityAlarmThreshold)
            .set(smogAlarmThreshold).equalTo(record::getSmogAlarmThreshold)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(System record) {
        return update(c ->
            c.set(company).equalToWhenPresent(record::getCompany)
            .set(contacts).equalToWhenPresent(record::getContacts)
            .set(tel).equalToWhenPresent(record::getTel)
            .set(temperatureAlarmThreshold).equalToWhenPresent(record::getTemperatureAlarmThreshold)
            .set(humidityAlarmThreshold).equalToWhenPresent(record::getHumidityAlarmThreshold)
            .set(smogAlarmThreshold).equalToWhenPresent(record::getSmogAlarmThreshold)
            .where(id, isEqualTo(record::getId))
        );
    }
}